﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public class Decoder
    {
        public static byte DecoderByte(ref List<byte> Source)
        {
            byte res = Source[0];
            Source.RemoveAt(0);
            return res;
        }
        public static Int32 DecoderInt32(ref List<byte> Source)
        {
            Int32 res= BitConverter.ToInt32(Source.ToArray(), 0);
            Source.RemoveRange(0, 4);
            return res;
        }
        public static Int64 DecoderInt64(ref List<byte> Source)
        {
            Int64 res = BitConverter.ToInt32(Source.ToArray(), 0);
            Source.RemoveRange(0, 8);
            return res;
        }
        public static string DecoderString(ref List<byte> Source)
        {
            string res = BitConverter.ToString(Source.ToArray(),0);
            Source.RemoveRange(0, res.Length);
            return res;
        }
        public static string DecoderString(ref List<byte> Source, int begin, int length)
        {
            string res = BitConverter.ToString(Source.ToArray(), begin,length);
            Source.RemoveRange(0, res.Length);
            return res;
        }
    }
}
